package cn.gok;

import java.util.*;
import java.util.stream.Stream;


class Book implements Comparable<Book>{
    private int bid;
    private  String bname;
    private  float price;

    public Book(int bid, String bname, float price) {
        this.bid = bid;
        this.bname = bname;
        this.price = price;
    }

    public int getBid() {
        return bid;
    }

    public void setBid(int bid) {
        this.bid = bid;
    }

    public String getBname() {
        return bname;
    }

    public void setBname(String bname) {
        this.bname = bname;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "Book{" +
                "bid=" + bid +
                ", bname='" + bname + '\'' +
                ", price=" + price +
                '}';
    }

    @Override
    public int compareTo(Book o) {
        if(this.getPrice()>o.price){
            return -1;
        }
        return 1;
    }
}

class BookCompartor implements Comparator<Book>{

    @Override
    public int compare(Book o1, Book o2) {
        if(o1.getBid()<o2.getBid()){
            return -1;
        }
        return 1;
    }
}
public class Homework {
    public static void main(String[] args) {
        TreeMap<Book,String> map= new TreeMap<>();
        map.put(new Book(1,"骆驼祥子",100.0f),"老六");
        map.put(new Book(2,"小人国",90.0f),"老林");
        map.put(new Book(3,"水浒传",102.5f),"老李");
        map.put(new Book(4,"史记",100.5f),"老武");
        map.put(new Book(5,"三国演会",110.0f),"老易");
        for (Book book:map.keySet()){
            System.out.println(book);
        }
        System.out.println("-------------");

        Iterator<Map.Entry<Book, String>> it = map.entrySet().iterator();
        while(it.hasNext()){
            Map.Entry<Book, String> e = it.next();
            System.out.println(e.getKey()+"---"+e.getValue());
        }

        System.out.println("----------");
        List<Book> arrayList=Arrays.asList(new Book(1,"西游记",100.0f),
                new Book(2,"小人国",90.0f),
                new Book(3,"史记",102.5f),
                new Book(4,"三国演义",160.5f),
                new Book(5,"骆驼祥子",110.0f));
        Stream<Book> stream=arrayList.stream();
        stream.filter((book)->{return book.getPrice()<150;}).sorted(new BookCompartor()).forEach(System.out::println);
    }
}